#nullable enable

using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using PHMEE.DTOS.Diagnosis;
using PHMEE.IServices.Diagnosis;

namespace PHMEE.Controllers.Diagnosis;

[Route("api/diagnosis/alarm-report")]
public class AlarmReportController : PHMEEController // , IAlarmReportAppService // 需 return File，不实现接口
{
    private readonly IAlarmReportAppService _alarmReportAppService;

    public AlarmReportController(IAlarmReportAppService alarmReportAppService)
    {
        _alarmReportAppService = alarmReportAppService;
    }
    
    /// <summary>
    /// 获取报警统计数据报表
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [Route("GetAlarmStatisticsReport")]
    [HttpGet]
    public Task<List<AlarmStatisticsDto>> GetAlarmStatisticsReportAsync(AlarmStatisticsRequestDto input)
    {
        return _alarmReportAppService.GetAlarmStatisticsAsync(input);
    }

    /// <summary>
    /// 导出报警统计数据报表
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [Route("ExportAlarmStatisticsReport")]
    [HttpGet]
    public async Task<FileResult> ExportAlarmStatisticsReportAsync(AlarmStatisticsRequestDto input)
    {
        var (stream, fileName) = await _alarmReportAppService.ExportAlarmReportAsync(input);
        return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", fileName);
    }
}